/*******************************************************************************
 *  DropdownControl class
 *  desc: Wrapper for DropdownElement
 *******************************************************************************

// example options object
var options = {
    id: 'id',
    name: 'name',
    type: 'text',
    placeholder: 'placeholder',   
    classes: 'classes',
    value: 'value',
    title: 'title'
}

*/

/**
 *  Represent dropdown control model
 */
var DropdownControl = function(options) {
    
    // this class should extend an ControlContainer class
    $.extend(true, this, new ControlContainer(options));
    
    // ------------------------------------------------------- settings
    this.defaults = {
    };
    
    var settings = this.prepareSettings(options);
    
    // ------------------------------------------------------- methods
    
    /**
     *  Sets list of options
     *  @param options defines list of options
     *  @return class instance
     */
    this.setList = function(options){
        this.fields[0].setList(options);
        return this;
    }
    
    this.clearList = function(){
        this.fields[0].clearList();
        return this;
    }
    
    this.setUnpreparedList = function(options){
        var list = options.list;
        var selectedValue = options.selectedValue;
        if(list){
            var result = new Array();
            if(options.needEmptyOption) result.push(EmptyOption());

            for(var i=0; i<list.length;i++){
                var o = list[i];
                if(selectedValue && selectedValue!='' && o.value == selectedValue){
                    o.selected = true;
                }
                result.push(uic.element.option(o));
            }
            this.setList(result);
        }
    }
    
    // ------------------------------------------------------- element creation
    var dropdown = new DropdownElement(settings);
    this.addElement(dropdown);
        
    console.log('DropdownControl was created with id = '+this.getId());
}